package cn.com.wind.bdg.collect.collect.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.text.StrBuilder;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.sun.tools.javac.resources.javac;
/**
 * 
 * @ClassName:  GetHTMLData   
 * @Description:获取详情页具体数据
 * @author: gaoxiang
 * @date:   2020年8月19日 下午12:31:49
 */
public class GetHTMLData {
	public static void  main(String[] args) throws Exception {
		List<String> resUrl = new ArrayList<String>();
		List<String> urlF = new ArrayList<String>();
		urlF.add("https://www.yaozs.com/data/ypgap/"); 
		urlF.add("https://www.yaozs.com/data/drugGap-htm-page-2-action-list.html");
		urlF.add("https://www.yaozs.com/data/drugGap-htm-page-3-action-list.html");
		for(int i=0;i<3;i++) {
			List<String> list = getUrl(urlF.get(i));
			for(int j=0;j<list.size();j++) {
				resUrl.add(list.get(j));
			}
		}
//		System.out.println(resUrl.size());
//		getCompanyName();
//		getType();
//		getLocation();
//		getArea();
		
	}
	
	
	public static List getUrl(String url) throws Exception {
    	List list = new ArrayList<String>();
    	Set<String> set = new HashSet<String>();
    	Document document = Jsoup.connect(url).get();
    	String doc = document.toString();
    	String regex = "/data/ypgap/.?.?/";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(doc);
		while(m.find()) {
			set.add(m.group());
		}
		Iterator<String> it = set.iterator(); 
		while (it.hasNext()) {
			list.add("https://www.yaozs.com"+it.next());
		}
		return list;
	}
	public List<String> getData() {
		List<String> list = new ArrayList<String>();
		
		return list;
	}
	public static String getCompanyName(String url) throws Exception{
//		String url = "https://www.yaozs.com/data/ypgap/1/";
		Document document = Jsoup.connect(url).get();
    	String doc = document.toString();
    	String regex = "公司名称：.*?\\n.*?</span>";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(doc);
		String str = null;
		while(m.find()) {
			str = m.group().replaceAll("公司名称：</label>\\n|<span>|</span>", "").trim();
		}
//		System.out.println(str);
		return str;
    	
    	
	}
	public static String getType(String url) throws Exception {
//		String url = "https://www.yaozs.com/data/ypgap/1/";
		Document document = Jsoup.connect(url).get();
    	String doc = document.toString();
    	String regex = "种植品种：.*?\\n.*?</span>";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(doc);
		String str = null;
		while(m.find()) {
			str = m.group().replaceAll("种植品种：</label>\\n|<span>|</span>", "").trim();
		}
//		System.out.println(str);
		return str;
		}
	public static String getLocation(String url) throws Exception {
//		String url = "https://www.yaozs.com/data/ypgap/1/";
		Document document = Jsoup.connect(url).get();
    	String doc = document.toString();
    	String regex = "注册地址：.*?\\n.*?</span>";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(doc);
		String str = null;
		while(m.find()) {
			str = m.group().replaceAll("注册地址：</label>\\n|<span>|</span>", "").trim();
		}
//		System.out.println(str);
		return str;
	}
	public static String getArea(String url) throws Exception {
//		String url = "https://www.yaozs.com/data/ypgap/1/";
		Document document = Jsoup.connect(url).get();
    	String doc = document.toString();
    	String regex = "种植区域：.*?\\n.*?</span>";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(doc);
		String str = null;
		while(m.find()) {
			str = m.group().replaceAll("种植区域：</label>\\n|<span>|</span>", "").trim();
		}
//		System.out.println(str);
		return str;
		}
	public static String getReportCode(String url) throws Exception {
//		String url = "https://www.yaozs.com/data/ypgap/1/";
		Document document = Jsoup.connect(url).get();
    	String doc = document.toString();
    	String regex = "公告号：.*?\\n.*?</span>";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(doc);
		String str = null;
		while(m.find()) {
			str = m.group().replaceAll("公告号：</label>\\n|<span>|</span>", "").trim();
		}
//		System.out.println(str);
		return str;
		}
}
